﻿using AutoMapper;
using CommonManagement.Applcation.Command;
using ERPPublic.eneity;
using MediatR;
using PersonnelManagement.Infrstructre.Interface;

namespace CommonManagement.Applcation.CommandHanlers
{
    public class ProvinceCommandHandlers : IRequestHandler<ProvinceCommand, List<Province>>
    {
        private readonly IProvinceRepository _provinceRepository;
        protected readonly IMapper mapper;
        public ProvinceCommandHandlers(IProvinceRepository _provinceRepository, IMapper mapper)
        {
            this._provinceRepository = _provinceRepository;
            this.mapper = mapper;
        }
        public async Task<List<Province>> Handle(ProvinceCommand request, CancellationToken cancellationToken)
        {
            var list = (await _provinceRepository.Getall()).ToList();
            return mapper.Map<List<Province>>(list);

        }
    }
}
